<?php 
	//PHP Scrolling - unfinished
	/*
	$script = $_SERVER['SCRIPT_NAME'];
	$query = $_SERVER['QUERY_STRING'];
	$scroll = 0;
	if (isset($_GET['scroll'])) {
		$scroll = (int)$_GET['scroll'];
	}
	$scrollUp = $scroll+1;
	$scrollDown = $scroll-1;
	*/
	$_GET['prefix'] = 'prj';
	if (!isset($_GET['ctg_id'])) {
		$_GET['ctg_id'] = $active_ctg_id;
	}
	include 'lib/php/load.php';
	ob_end_clean();
	$projects = $items;
	
	/*
	$projectNum = count($projects);
	if ($scrollUp != 0 && abs($projectNum / $scrollUp) >= 6) {
		echo '<div id="projectUp" class="arrowUp"><a href="', $script, "?", $query, "&scroll=", $scrollUp, "></a></div>";
	}*/
	?>
	<div id="projectContainer" class="nav nav_vertical">
	<div id="projectScrollBox" class="scrollBox">
	
	<?php
	$s = 0;
	foreach ($projects as $id => $item) {
		if(isset($_GET['prj_id'])) {
			//if ($s > ($projectNum - abs($scroll*6))) {
				if($id == $_GET['prj_id']) {
					$active_prj_id = $id;
					displayPrj($id, $item, true);
				} else {
					displayPrj($id, $item, false);
				}
			//}
		} else {
			displayPrj($id, $item, false);
		}
		$s++;
	}
?>
</div>
</div>
<!--  <div id="projectDown" class="arrowDown"><a href="<?php //echo $_SERVER['SCRIPT_NAME']."?". $_SERVER['QUERY_STRING']."&scroll=".$scrollDown; ?>"></a></div> -->

<?php 
function displayPrj($id, $item, $active){
	$prefix = $item[prefix];
	$div_id = $prefix."_".$id;
	$alias = $item[alias];
	$label = $item[label];
	$thumb = $item[thumb];
	$thumb_enable = $item[thumb_enable];
	$top = 80*$item[position];
	$link = $item[link];
	$link_enable = $item[link_enable];
	$ctg = $item[category_id];
	$class_active = $active == true ? 'active' : '';
	$class = 'item prj'.' '.$item[item_class].' '.$class_active;
	
	
	$html = array("<div id='$div_id' class='$class' style='top:".$top."px;'>");
	if(!empty($thumb) && $thumb_enable) 	array_push($html, "	<img id='thumb_$div_id' class='thumb' src='$thumb' alt='$alias' width='73' height='73' />\n");
	if(!empty($label)) 						array_push($html, "	<div id='label_$div_id' class='label'>$label</div>\n");
	if(!empty($link) && $link_enable)		array_push($html, "	<a id='outerlink_$div_id' class='link nav outer' href='$link' target='_blank'></a>\n");
	else 									array_push($html, " <a id='innerlink_$div_id' class='link nav inner' href='index.php?prefix=$prefix&amp;ctg_id=$ctg&amp;prj_id=$id'></a>\n");		
											array_push($html, "</div>");
	echo join('', $html);
}
?>